// packageA/pages/orderinf/orderinf.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    all_list: null

  },
  gettime(time) {
    var n = parseInt(time);
    var D = new Date(n);
    var year = D.getFullYear();//四位数年份

    var month = D.getMonth() + 1;//月份(0-11),0为一月份
    month = month < 10 ? ('0' + month) : month;

    var day = D.getDate();//月的某一天(1-31)
    day = day < 10 ? ('0' + day) : day;

    var hours = D.getHours();//小时(0-23)
    hours = hours < 10 ? ('0' + hours) : hours;

    var minutes = D.getMinutes();//分钟(0-59)
    minutes = minutes < 10 ? ('0' + minutes) : minutes;
    var now_date = month + '-' + day;
    var now_time = hours + ':' + minutes;
    return { now_date, now_time }
  },
  getdata() {
    wx.cloud.database().collection('login_orderList').where({ _openid: wx.getStorageSync('openid') }).get().then(res => {
      for (let i = 0; i < res.data.length; i++) {
        let dats = res.data[i].order_state;
        res.data[i]['pay_time_String'] = (new Date(res.data[i].pay_time)).toLocaleString();
        for (let j = 0; j < dats.length; j++) {
          let time_data = this.gettime(dats[j].pay_time);
          res.data[i].order_state[j]['now_date'] = time_data.now_date;
          res.data[i].order_state[j]['now_time'] = time_data.now_time;
        }
      }
      console.log(res)
      this.setData({ all_list: res.data.reverse() });
    })
  },

  loopsd(e) {
    let itemsd = e.currentTarget.dataset.item;
    app.globalData.loop_data = itemsd;
    wx.navigateTo({
      url: '/packageA/pages/orderinf_look/orderinf_look',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getdata()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})